package com.thread.prodcustrom;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestSync {

	static Lock mLock = new ReentrantLock();

	public static void main(String args[]){

		new Thread(new Runnable() {
			@Override
			public void run() {
				int i = 0;
				while (true){
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
					}
					i++;
					mLock.lock();
					testPrintln(i);
					mLock.unlock();
				}

			}
		}).start();


		new Thread(new Runnable() {
			@Override
			public void run() {
				int i = 0;
				while (true){
					try {
						Thread.sleep(5000);
					} catch (InterruptedException e) {
					}
					i++;
					mLock.lock();
					testPrintln(i);
					mLock.unlock();
				}

			}
		}).start();
	}

	private  static void testPrintln(int i){
			System.out.println(Thread.currentThread().getName()+i);
	}
}
